package com.tdam.g12.adapters;

import java.util.ArrayList;

import com.tdam.g12.soporte.Historial;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class HistorialAdapter extends BaseAdapter
{
	private ArrayList<Historial> listaHistorial;
	private LayoutInflater inflater;
	
	public HistorialAdapter (Context context){
		listaHistorial= new ArrayList<Historial>();
		inflater = LayoutInflater.from(context);	
	}
	
	public void clear() 
	{
		listaHistorial.clear();
	}
	
	@Override
	public int getCount()
	{
		// TODO Auto-generated method stub
		return listaHistorial.size();
	}

	@Override
	public Object getItem(int position)
	{
		// TODO Auto-generated method stub
		return listaHistorial.get(position);
	}

	@Override
	public long getItemId(int position)
	{
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		// TODO Auto-generated method stub
		Holder holder = null;
		
		if (convertView == null) 
		{
			convertView = inflater.inflate(com.tdam.g12.R.layout.item_historial, null);
			holder = new Holder();
			holder.type = (TextView) convertView.findViewById(com.tdam.g12.R.id.txtType);
			holder.address = (TextView) convertView.findViewById(com.tdam.g12.R.id.txtAddress);
			holder.date = (TextView) convertView.findViewById(com.tdam.g12.R.id.txtDate);
			convertView.setTag(holder);
		} 
		else 
		{
			holder = (Holder) convertView.getTag();
		}

		Historial itemHistoria = (Historial) listaHistorial.get(position);
		
		holder.type.setText(itemHistoria.getType());
		holder.address.setText(itemHistoria.getIdContacto());
		holder.date.setText(itemHistoria.getDate());

		return convertView;
	}
	
	public void addItem(Historial itemHistoria){
		if (itemHistoria != null) 
		{
			listaHistorial.add(itemHistoria);
		}
	}
	
	class Holder 
	{
		private TextView type;
		private TextView address;
		private TextView date;
	}
}
